console.log("🔥 Background Script Running");

// ==============================
// 🚀 START BOOKING LISTENER
// ==============================

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {

  if (message.action === "START_BOOKING") {

    console.log("🚆 Opening IRCTC...");

    chrome.tabs.create({
      url: "https://www.irctc.co.in/nget/train-search"
    }, (tab) => {
      sendResponse({ status: "opened" });
    });

    return true;
  }

});


chrome.runtime.onMessage.addListener((msg, sender) => {

  if (msg.action === "START_BOOKING") {

    chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {

      chrome.scripting.executeScript({
        target: { tabId: tabs[0].id },
        files: ["mycontrol.js"]
      });

    });

  }

});



// ==============================
// ✅ ON INSTALL
// ==============================

chrome.runtime.onInstalled.addListener(() => {
  console.log("✅ Extension Installed Successfully");
});